const router = require('koa-router')()
const {
    dynamicList,
    dynamicAdd,
    dynamicMyList
} = require('../controller/dynamic')

router.prefix('/api/dynamic')

//动态列表
router.get('/list', async (ctx, next) => {
    const {
        pageIndex,
        pageSize
    } = ctx.query
    const dynamicData = await dynamicList({
        pageIndex,
        pageSize
    })
    ctx.body = dynamicData
})

//我的动态
router.get('/my', async (ctx, next) => {
    const {
        pageIndex,
        pageSize,
        userId
    } = ctx.query
    const dynamicMyData = await dynamicMyList({
        pageIndex,
        pageSize,
        userId
    })
    ctx.body = dynamicMyData
})

//动态添加
router.post('/add', async (ctx, next) => {
    const {
        title,
        url,
        userId,
        type
    } = ctx.request.body
    ctx.body = await dynamicAdd({
        title,
        url,
        userId,
        type
    })
})

module.exports = router
